import './init.js' // 一些初始化执行的代码
import { getDictList } from "@/utils/util.js" // 查询字典表方法
import axios from 'axios' // axios请求
import checkRole from '@/utils/checkRole'
import regCheck from './regCheck'

import * as allMethod from './tools'

export default {
  install(Vue) {
    Vue.prototype.getDictList = getDictList
    Vue.prototype.axios = axios
    Vue.prototype.regCheck = regCheck
    Vue.prototype.$CheckRole = checkRole
    Vue.prototype.$selectDict = function (dictList, dictValue) {
      if(dictList && dictList.length) {
        let data = dictList.filter(el => el.dictValue == dictValue)
        if (data.length == 0) {
          data = [{ dictLabel: '-', dictValue: null }]
        }
        return data[0]
      } else {
        return { dictLabel: '-', dictValue: null }
      }
    }
    // 根据出生年月计算年龄
    Vue.prototype.$getAgeByBirth = function (year) {
      return new Date().getFullYear() - new Date(year).getFullYear()
    }
    Object.keys(allMethod).forEach(el => {
      Vue.prototype[el] = allMethod[el]
    })
  }
}
